<% content_for :title, "Visualiser #{@computer.name}" %>
<% content_for("page_header") do %>
<%= stylesheet_link_tag 'computers.css' %>
<% end %>

<% if @error %>
	<div class="error">Ordinateur introuvable</div>

	<%= link_to "Voir la liste des ordinateurs",
			computers_path,
			:class => "button bg_orange list"
			%>

<% else %>
	<div id="side-left">
		<%= image_tag("icons/host.png") %>
		<p>
		  <b>Nom de la machine:</b>
		  <%=h @computer.name %>
		</p>
		<p>
	  <b>Salle:</b>
	  <%=h @computer.room.name %>
	</p>
	<p>


		<%= image_tag('icons/ajax-loader.gif' ,:style =>'display:none',:id=> 'loader_agent') %>
		<%= link_to_remote  image_tag("icons/agent.png", :border=>0, :alt=>"tester l'agent",:title=>"tester l`agent"),
			{:url=>{:controller => "computers", :action => "agent", :id => @computer },
			:loading=>visual_effect(:appear, 'loader_agent'),
			:loaded=>visual_effect(:blind_up, 'loader_agent', :duration => 10) },
			:href=>url_for(:controller => "computers", :action => "agent", :id => @computer)
			%>
		</p>

		
	</div>


	<div id="side-right">
		<% if current_user %>
	<div class="fieldset">
		<h2>Administration</h2>
		<div class="block">
		<p>
			<%= link_to image_tag("icons/edit.png", :title=>"Modifier l'ordinateur"),
					edit_computer_path(@computer)
					%>
		
			<%= link_to_remote image_tag("icons/ping.png", :title=>"Pinger l\'ordinateur"),
							{
								:url=>{:controller => :computers, :action => :ping, :id => @computer.id},
								:loading=>visual_effect(:appear, 'loader_computer'),
								:loaded=>visual_effect(:blind_up, 'loader_computer', :duration => 2),
							},
							:href=>(url_for :controller => :computers, :action=>:ping, :id => @computer.id)

						%> 
			<%= image_tag('icons/ajax-loader.gif' ,:style =>'display:none',:id=> 'loader_computer') %>
		
			<%= link_to_remote image_tag("icons/update.png", :title=>"Mettre à jour l\'antivirus"),
							{
								:url=>{:controller => :computers, :action => :update_av, :id => @computer.id},
								:loading=>visual_effect(:appear, 'loader_av'),
								:loaded=>visual_effect(:blind_up, 'loader_av', :duration => 2),
							},
							:href=>(url_for :controller => :computers, :action => :update_av, :id => @computer.id)

						%> 
			<span id="av_update_statut"></span>
			<%= image_tag('icons/ajax-loader.gif' ,:style =>'display:none',:id=> 'loader_av') %>
		</p>

		<p>
			<label>Dernière mise à jour de l'antivirus : </label>
			<div id="<%= "av_update_#{@computer.id}" %>">
				<% if @av_update_date %>
					<%= @av_update_date %>
				<% else %>
					Aucune MAJ
				<% end %>
			</div>
		</p>

		</div>
	</div>
	<% end %>
		<div class="fieldset">
			<h2>Système</h2>
			<div class="block">
			
		<p>
			<b>Système d'exploitation:</b>
			<%=h @computer.os %>
		</p>
		<p>
			<b>Antivirus:</b>
			<%=h Softwares.find_by_id (@computer.software_id).name %>
			</p>
				<p>
					<b>Ram:</b>
					<%=h @computer.ram %>Mo
				</p>
				<p>
				  <b>Cpu:</b>
				  <%=h @computer.cpu %>GHz
				</p>
				<p>
				  <b>Disque dur:</b>
				  <%=h @computer.hard_drive %>Go
				</p>    
			</div>
		</div> 
			
		<div class="fieldset">
			<h2>Réseaux</h2>
			<div class="block">	
				<p>
					<b>Adresse ip de la machine:</b>
					<%=h @computer.ip_computer %>
				</p>    
				<p>
					<b>Adresse mac de la machine:</b>
					<%=h @computer.mac_adress %>
				</p>
				</div>
			</div>
			<div class="fieldset">
				<h2>Etat</h2>
				<div class="block">
		
				<p>		          
					<b>Statut de l'agent:</b>
					   <% if @computer.state_agent %>
						<%= image_tag "icons/active.png", :id=>"agent_state_#{@computer.id}" %>
					 <% else %>
						<%= image_tag "icons/inactive.png", :id=>"agent_state_#{@computer.id}" %>
					<% end %>	
				</p>
				<p>
				<b>Statut de la machine:</b>
				 <% if @computer.state_computer %>
					<%= image_tag "icons/active.png", :id=>"computer_state_#{@computer.id}" %>
				 <% else %>
					<%= image_tag "icons/inactive.png", :id=>"computer_state_#{@computer.id}" %>
				<% end %>	
				</p>
				</div>
			</div>
	</div>

	<%= link_to "Voir la liste des ordinateurs",
			computers_path,
			:class => "button bg_orange list"
			%>

	<%= javascript_include_tag :defaults %>
	<%= link_to_remote "Historique des incidents", {:url => { :controller => "computers", :action => "toggle" }}, :class => "button calendar" %>
		
<script type="text/javascript">
		jQuery(document).ready(function() {

		jQuery("#rjs-testbed").hide();
		});
</script>
		
		
		<div id="rjs-testbed">
			<table>
				<tr>
					<th>Informations</th>
					<th>Date de création</th>
					<th>Date de résolution</th>
					<th>Etat</th>
					<th>Type de l'évènement</th>
					<th>Action</th>
				</tr>
				<% @events.each do |event| %>
				<%  # change background for event updated less than 3 minutes ago
					if 3.minutes.ago.to_formatted_s(:db) < event.date_resolution
						tr_class = ' class="bg_orange"'
					else
						tr_class = ''
					end
				%>
				<tr<% tr_class %>>
					<td><%= event.event_info %></td>
					<td><%= event.date_creation %></td>
					<td>
						<% if event.state_event=="1" %>
							<%=h "non résolu"  %>
						<% else %>
							<%= event.date_resolution %>
						<% end %>
					</td>
					<td>
						<% if event.state_event=="1" %>
							<%=h "non résolu"  %>
						<% else %>
							<%=h "résolu"  %> 
						<% end %>
					</td> 
					<td><%= event.type_event %></td>
				    <td><%= link_to image_tag("icons/zoom.png", :title=>"Afficher"), @computer %>
				    	<% if current_user %>
					    	<%= link_to image_tag("icons/edit.png", :title=>"Modifier"),edit_computer_path(@computer) %>
					    	<%= link_to image_tag("icons/delete.png", :title=>"Supprimer"), @computer, :confirm => 'Are you sure?', :method => :delete %></td>
					    <% end %>
				</tr>
				<% end %>
			</table>
		</div>
	</div>
<% end %>
